#ifndef DOOR_DETECTOR_H
#define DOOR_DETECTOR_H

#include "line.h"
#include "Splitter.h"
#include <vector>

class DoorDetector 
{
public: 
  struct DoorData {
    line::point_type center;
    line::point_type first;
    line::point_type second;	
    double width;
    double thetaNorm;
    double distance;
  };
  typedef DoorData door_type;
  typedef std::vector<door_type> door_vector;

  /** Creates a door detector that uses the parameters in the given 
   * configuration file.
   */
  DoorDetector(std::string configFilename);

  /** Destructor.
   */
  ~DoorDetector();

  /** Returns a vector of door descriptors extracted from the given scan.
   */
  void findDoors(const line::point_vector& scan,door_vector& doors);

private:
  line::Splitter* splitter_;
  double DOOR_WIDTH_MEAN;
	double DOOR_WIDTH_TOLL;
	double DOOR_ALLIGN_THR;
	double DOOR_PILLAR_MIN_SIZE;

	double DOOR_INT_SPLITTER_BASE;
  double DOOR_INT_SPLITTER_STEP;
  double DOOR_END_SPLITTER_TH;
  double DOOR_END_SPLITTER_LEVEL;
  int DOOR_END_SPLITTER_POINTNUM;
	
  double alignment(line::point_type pmin,line::point_type pmax,
                   line::point_type qmin,line::point_type qmax);

  double gapSize(line::point_type pmin,line::point_type pmax,
                 line::point_type qmin,line::point_type qmax);

  void swapPoint(line::point_type& p1,line::point_type& p2,
                 line::point_type& q1,line::point_type& q2);

  double distance(line::point_type p1,line::point_type p2);
  
  void plotGnuplot(const line::point_vector& scan,line::interval_vector& iv,door_vector& doors);
};

#endif 

